package com.traffic.between.adaptor;

import java.util.Date;

import org.apache.log4j.Logger;

import com.traffic.between.annotation.ChooseProvider;
import com.traffic.between.config.OrderInfoContext;
import com.traffic.between.redis.running.BsmOrderResultExecutor;
import com.traffic.between.service.RongJingServiceImpl;
import com.traffic.managent.service.order.bean.OrderBean;

import net.sf.json.JSONObject;

@ChooseProvider(channel = "rongjing")
public class RongJingAdaptor implements IAdaptor {

	private static Logger log = Logger.getLogger(RongJingAdaptor.class);

	public void order() {
		
	    OrderBean orderBean = OrderInfoContext.getContext();
	    orderBean.setSendTime(new Date());
		String pkgNo = orderBean.getProductCode();
		String phoneNo = orderBean.getPhoneNo();
		String tradeNo = orderBean.getIds();//订购流水号
		String region  = orderBean.getRegion();// 0 - 全国     1 - 省
		
		
		String result = RongJingServiceImpl.service.order(pkgNo,phoneNo,tradeNo,region);
		log.info("between- 荣景RongJingService.order() 订购请求result<>:" + result);
	
	
		JSONObject json = JSONObject.fromObject(result);

		String status = json.getString("status");//状态码

		if ("0000".equals(status)) {
			orderBean.setStatus("10");
			orderBean.setMessage(json.getString("message"));
			orderBean.setErrorMsg(json.getString("message"));	
			JSONObject resultJson = JSONObject.fromObject(json.getString("result"));
			orderBean.setSuppOrderNo(resultJson.getString("orderid"));
		
		} else {
			orderBean.setStatus("8");
			orderBean.setMessage(json.getString("message"));
			orderBean.setErrorMsg(json.getString("message"));
			
		}
		
		BsmOrderResultExecutor.service.setOrder(orderBean);
	}

	
}
